//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.restaurant.application.indexes.signinlist;

import com.nebutown.base.ViewSpec;
import com.nebutown.base.data.View;
import com.nebutown.base.data.ViewUpdate;
import com.nebutown.commonunits.dataface.DataModes;
import com.nebutown.commonunits.dataface.FormShell;
import com.nebutown.commonunits.dataface.TableShell;
import com.nebutown.commonunits.dataface.definitions.FieldValue;
import com.nebutown.commonunits.dataface.definitions.PageForm;
import com.nebutown.commonunits.dataface.definitions.PageInfo;
import com.nebutown.commonunits.uidataface.UIDataFace;
import com.nebutown.commonunits.utils.DateTimeUtils;
import com.nebutown.description.data.SortSpec;
import com.restaurant.application.indexes.signinlist.mysql.SignInListBean;
import com.restaurant.application.indexes.signinlist.mysql.SignInListCriteria;
import com.restaurant.application.indexes.signinlist.mysql.SignInListImpl;
import com.restaurant.application.indexes.signinlist.support.AbstractAssistSignInList;
import java.util.List;

public class AssistSignInListImpl extends AbstractAssistSignInList {
    public AssistSignInListImpl() {
    }

    public ViewUpdate doSearchPath(SignInListCriteria data, int[] seq) {
        return this.returnView(new View[]{this.newCommonTable(data, 1)});
    }

    public View getFullView() {
        return this.newCommonTable(new SignInListCriteria(), 1);
    }

    public View getViewLead(ViewSpec viewSpec) {
        return null;
    }

    private View newCommonTable(SignInListCriteria criteria, int pageNum) {
        int pageSize = 10;
        int start = (pageNum - 1) * pageSize;
        int stop = pageNum * pageSize;
        int totalRecord = ((SignInListImpl)this.getIndex(SignInListImpl.class)).count(criteria);
        int totalPage = (totalRecord + pageSize + 1) / pageSize;
        List<SignInListBean> signInList = ((SignInListImpl)this.getIndex(SignInListImpl.class)).search(criteria, (SortSpec)null, start, stop);
        PageInfo pageInfo = (new PageInfo()).withPageNum(pageNum).withPageSize(Integer.valueOf(pageSize)).withTotalPage(totalPage).withTotalRecord(totalRecord);
        PageForm pageForm = this.newFormShell(criteria, signInList).getForm();
        return ((UIDataFace)this.getSingleton(UIDataFace.class)).newUniForm(this.unitPosition(), pageForm);
    }

    private FormShell newFormShell(SignInListCriteria criteria, List<SignInListBean> signInList) {
        FormShell formShell = new FormShell("会员签到", 3, 2);
        formShell.source(criteria, DataModes.EDIT);
        formShell.at(0, 0, "客户名称").stringField("customerNameLike", criteria.getCustomerNameLike()).placeHolder("客户名").setEditable(true);
        formShell.at(0, 1, "搜索").buttonField(this.getPath(CMD_DOSEARCHPATH, new int[0]), "", "", true);
        TableShell<SignInListBean> tableShell = new TableShell(SignInListBean.class, signInList);
        tableShell.createColumn("customerName").withName("会员名").cellCalculator((b) -> {
            SignInListBean bean = (SignInListBean)b;
            return (new FieldValue()).withValue(bean.getCustomerName());
        });
        tableShell.createColumn("recordId").withName("签到时间").cellCalculator((b) -> {
            SignInListBean bean = (SignInListBean)b;
            return (new FieldValue()).withValue(DateTimeUtils.toTime(bean.getSignTime()));
        });
        formShell.at(2, 0, "会员签到列表").large(3, 1).tableField(tableShell);
        return formShell;
    }
}
